class LinksController < ApplicationController
  before_action :set_link, only: [:show]

  def index
    @links = Link.all
  end

  def new
    @link = Link.new
  end

  def create
    @link = Link.new link_param
    if @link.save
      redirect_to links_path, notice: 'Link was successfully created'
    else
      render :new, alert: 'Cannot create link.'
    end
  end

  def show; end

  private

  def link_param
    params.require(:link).permit(:url)
  end

  def set_link
    @link = Link.find params[:id]
  end
end